package com.dreamlin.gankio.mvvm.home

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.dreamlin.gankio.R
import com.dreamlin.gankio.base.ui.NoVMFragment
import com.dreamlin.gankio.mvvm.home.feature.FeatureFragment
import com.dreamlin.gankio.mvvm.home.other.OtherFragment
import com.google.android.material.tabs.TabLayout
import kotlinx.android.synthetic.main.fragment_home.*

/**
 * <p> Title: HomeFragment </p>
 * <p> Description: </p>
 * @author:  dreamlin
 * @date:    9/20/20
 * @version: V1.0.0
 * Created by dreamlin on 9/20/20.
 */
class HomeFragment : NoVMFragment() {
    override val layout: Int
        get() = R.layout.fragment_home

    override fun initViews() {
        val tabs = resources.getStringArray(R.array.tabs)
        viewPager.offscreenPageLimit = 1
        viewPager.adapter = object : FragmentStateAdapter(this) {
            override fun getItemCount(): Int {
                return tabs.size
            }

            override fun createFragment(position: Int): Fragment {
                return if (position == 0)
                    FeatureFragment()
                else {
                    val otherFragment = OtherFragment()
                    val bundle = Bundle()
                    bundle.putString("TAB", tabs[position])
                    otherFragment.arguments = bundle
                    otherFragment
                }
            }

            /*override fun getItem(position: Int): Fragment {
                return if (position == 0)
                    FeatureFragment()
                else {
                    val otherFragment = OtherFragment()
                    val bundle = Bundle()
                    bundle.putString("TAB", tabs[position])
                    otherFragment.arguments = bundle
                    otherFragment
                }
            }

            override fun getCount(): Int {
                return tabs.size
            }

            override fun getPageTitle(position: Int): CharSequence? {
                return tabs[position]
            }*/
        }
        tabLayout.setViewPager(viewPager, tabs)
    }

    override fun click(v: View) {

    }

    override fun initData() {

    }

}